<template>
    <h1>组合式api</h1>
    <div class="box box1" ref="box1Ref">
        <p>width: {{ width }}</p>
        <p>height: {{ height }}</p>
        <p>x: {{ x }}</p>
        <p>y: {{ y }}</p>
    </div>
    <div class="box box2" ref="box2Ref">
        <p>width: {{ width2 }}</p>
        <p>height: {{ height2 }}</p>
        <p>x: {{ x2 }}</p>
        <p>y: {{ y2 }}</p>
    </div>
</template>
<script setup>
import { ref } from 'vue'
const box1Ref = ref(null)
const box2Ref = ref(null)

import { useElementRect } from './useElementRect'
const { width, height, x, y } = useElementRect(box1Ref)
const { width: width2, height:height2, x:x2, y:y2 } = useElementRect(box2Ref)

</script>
<style>
   * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
   }
    .box {
        background: #040D19;
        border-radius: 12px;
        color: #fff;
        text-align: center;
        margin: 20px;
        padding-top: 20px;
    }
    .box1 {
        width: 200px;
        aspect-ratio: 1 / 1;
    }
    .box2 {
        width: 260px;
        aspect-ratio: 1 / 1;
    }
</style>